package com.suray.basic.wcs.plc.pojo.oper;

import com.suray.basic.wcs.plc.core.PlcOffset;
import com.suray.basic.wcs.plc.enums.PlcDeviceType;
import com.suray.basic.wcs.plc.enums.Location;
import com.suray.basic.wcs.plc.pojo.DeviceBase;
import com.suray.basic.wcs.utils.Coord;

/**
 *
 * @author shaozn
 * @date 2020/1/22 - 13:49
 * @Description 工位监控对象
 */
public class StationOper extends DeviceBase {
    private static final PlcOffset PALLET_NO = new PlcOffset(0, null);
    private static final PlcOffset PALLET_EXIST = new PlcOffset(1, 8);
    private static final PlcOffset RUN_ING = new PlcOffset(1, 9);
    private static final PlcOffset CAN_PUT = new PlcOffset(1, 10);
    private static final PlcOffset CAN_GET = new PlcOffset(1, 11);
    private static final PlcOffset IS_ERROR = new PlcOffset(1, 12);
    private static final PlcOffset SPARE_1 = new PlcOffset(1, 13);
    private static final PlcOffset SPARE_2 = new PlcOffset(1, 14);
    private static final PlcOffset SPARE_3 = new PlcOffset(1, 15);


    public StationOper(PlcDeviceType plcDeviceType, int startNo, String deviceName, int deviceNo, Coord coord,
                       Location location, Coord lockLocation, long deviceId, Integer gridzMax, Integer gridzRelative,
                       int plcId) {
        super(plcDeviceType, startNo, deviceName, deviceNo, coord, location, lockLocation, deviceId, gridzMax,
                gridzRelative, plcId);
    }


    public Integer getPalletNo() {
        return readPlc(PALLET_NO);
    }

    public boolean isPalletExist() {
        return readPlc(PALLET_EXIST) == 1;
    }

    public boolean isRunIng() {
        return readPlc(RUN_ING) == 1;
    }

    public boolean isCanPut() {
        return readPlc(CAN_PUT) == 1;
    }

    public boolean isCanGet() {
        return readPlc(CAN_GET) == 1;
    }

    public boolean isError() {
        return readPlc(IS_ERROR) == 1;
    }

    @Override
    public String toString() {
        return "Station{" +
                "palletNo=" + getPalletNo() +
                ", palletExist=" + isPalletExist() +
                ", runIng=" + isRunIng() +
                ", canPut=" + isCanPut() +
                ", canGet=" + isCanGet() +
                ", isError=" + isError() +
                '}';
    }
}
